package com.rpcdemo.rpc;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 单例分发器
 */
public class Dispatcher {
    private static class DispatcherHolder{
        public static Dispatcher dispatcher = new Dispatcher();
    }

    private Dispatcher() {
    }

    public static Dispatcher getDispatcher() {
        return DispatcherHolder.dispatcher;
    }

    private static ConcurrentHashMap<String, Object> invokeMapping = new ConcurrentHashMap<>();

    public void register(String k, Object impl) {
        invokeMapping.put(k, impl);
    }

    public Object get(String k) {
        return invokeMapping.get(k);
    }

}
